<?php
/**
 * Created by 王跃达.
 * User: 小马出行
 * Date: 2017/8/24
 * Time: 16:17
 */

namespace app\api\model;


use think\Db;
use think\Model;

class CouponModel extends Model
{


    public function __construct()
    {
        parent::__construct();

    }

    /*
     * 获取uid优惠券
     */
    public function getCouponByUid($uid)
    {
        $where['uid'] = $uid;
        $where['end_time'] = array(array(">", time()), array("=", 0), 'or');
        $where['is_use'] = 2;
        return Db::table('xm_coupon')->where($where)->order("coupon_id desc")->select();
    }

    public function updateCoupon($map,$data)
    {
        return Db::table('xm_coupon')->where($map)->update($data);
    }

    public function getCoupon($map,$field='*',$flag = true,$order='coupon_price desc',$page=1,$limit=10)
    {
        return $flag ? Db::table('xm_coupon')->where($map)->field($field)->order($order)->page($page,$limit)->select()
            :Db::table('xm_coupon')->where($map)->field($field)->order($order)->find();
    }


}